package com.example.rdb.conf.redis;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author XYC
 * @描述: TODO
 * @date 20.12.214:30
 */
@EnableCaching
@Configuration
public class WriteRedisConfig extends RedisConfig{


    @Value("${spring.redis-write.database}")
    private int dbIndex;

    @Value("${spring.redis-write.host}")
    private String host;

    @Value("${spring.redis-write.port}")
    private int port;

    @Value("${spring.redis-write.password}")
    private String password;

    /**
     * 配置redis连接工厂
     *
     * @return
     */
    @Bean
    public RedisConnectionFactory cacheRedisConnectionFactory() {
        return redisConnectionFactory(host, port, password, dbIndex);
    }

    /**
     * 配置redisTemplate 注入方式使用@Resource(name="") 方式注入
     *
     * @return
     */
    @Bean(name = "cacheRedisTemplate")
    public RedisTemplate cacheRedisTemplate() {
        return redisTemplate(cacheRedisConnectionFactory());
    }
}
